package com.crealth.crmserver;

import java.util.concurrent.TimeUnit;

import org.apache.log4j.Logger;

public abstract class CommonThread extends Thread  {
	private static final int START_DELAY = 1;
	private static final int SLEEP_TIME = 16;
	protected static final Logger logger = Logger.getLogger("running_log");
	private static Logger errorLog = Logger.getLogger("error_log");
	
	@Override
	public void run() {
		Thread.currentThread().setName("QueueThread - " + getId());
		
		try {
			TimeUnit.SECONDS.sleep(START_DELAY);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		while (true) {
			try {
				execute();
			} catch (Exception e) {
				errorLog.error("Thread Exception happend", e);
			}
			
			try {
				TimeUnit.MILLISECONDS.sleep(SLEEP_TIME);
			} catch (InterruptedException e) {
				errorLog.error("Thread put Exception happend", e);
			}
		}
	}
	
	// 执行一次处理
	public abstract void execute() throws Exception;
}
